﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class CartdetailDAO:IData<Cartdetail> 
 	{
		public CartdetailDAO(String myconnecString) : base(myconnecString) { }

		public override int OnSubmit(Cartdetail item, int t) {
			 return connec.ExecuteNonQuery("sp_Cartdetail", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Cartdetail.c_id, item.id), new SqlParameter("@" + Cartdetail.c_cartId, item.cartId),
				 new SqlParameter("@" + Cartdetail.c_productId, item.productId), new SqlParameter("@" + Cartdetail.c_numberOf, item.numberOf),
				 new SqlParameter("@" + Cartdetail.c_unitPrice, item.unitPrice)); 
		}

		public override Cartdetail GetItem(IDataReader dr)
		{
			Cartdetail obj = new Cartdetail();
			obj.id = Convert.ToInt64(dr[Cartdetail.c_id]);
			obj.cartId = Convert.ToInt64(dr[Cartdetail.c_cartId]);
			obj.productId = Convert.ToInt64(dr[Cartdetail.c_productId]);
			obj.numberOf = Convert.ToInt32(dr[Cartdetail.c_numberOf]);
			obj.unitPrice = Convert.ToDecimal(dr[Cartdetail.c_unitPrice]);
			return obj;
		}

		public override List<Cartdetail> GetAll()
		{
			return GetAll("select * from " + Cartdetail.b_Cartdetail, CommandType.Text);
		}

		public override Cartdetail GetItemById(object id)
		{
			throw new NotImplementedException();
		}

	}

 }
